package com.zut.utils;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;

public class DBUtils {

	private static String Driver = "com.mysql.jdbc.Driver";
	private static String URL = "jdbc:mysql://localhost:3306/apartment";
	private static String USER = "root";
	private static String PASSWORD = "123456";
	
	/*
	 * 创建连接池BasicDataSource
	 */
	public static BasicDataSource dataSource = new BasicDataSource();

	
	//静态代码块
	static {
		//对连接池对象 进行基本的配置
		dataSource.setDriverClassName(Driver); // 这是要连接的数据库的驱动
		dataSource.setUrl(URL); //指定要连接的数据库地址
		dataSource.setUsername(USER); //指定要连接数据的用户名
		dataSource.setPassword(PASSWORD); //指定要连接数据的密码
	}
	/*
	 * 返回连接池对象
	 */
	public static DataSource getDataSource(){
		return dataSource;
	}
	
}
